home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 23
/
CU Amiga - Super CD-ROM 23 (June 1998).iso
/
CUCD
/
Online
/
AMarquee
/
examples
/
streamgen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-02-20
|
3KB
|
98 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos/dos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/AMarquee_protos.h>
#include <pragmas/AMarquee_pragmas.h>
#define UNLESS(x) if (!(x))
struct Library * AMarqueeBase = NULL;
struct QSession * session = NULL;
void CleanExit(void)
{
if (session) QFreeSession(session); /* This MUST be done before we close the library! */
if (AMarqueeBase) CloseLibrary(AMarqueeBase);
printf("All done.\n");
}
/* Main program--simply increments our counter using a stream. */
int main(int argc, char ** argv)
{
char * connectTo, * progName;
int port = 2957;
int count = 0;
atexit(CleanExit);
printf("StreamGen: This program continually updates an integer on the server.\n");
printf(" It uses QStreamOp(), so anyone subscribing to streamcount\n");
printf(" should see a monotonously increasing stream of integers.\n\n");
printf("Usage Note : StreamGen [host=hostname] [name=streamgen]\n");
connectTo = (argc > 1) ? argv[1] : "localhost";
progName = (argc > 2) ? argv[2] : "streamgen";
if ((AMarqueeBase = OpenLibrary("amarquee.library",37L)) == NULL)
{
printf("Couldn't open amarquee.library v37!\n");
exit(RETURN_ERROR);
}
printf("Connecting to %s:%i...\n",connectTo, port);
if ((session = QNewSession(connectTo, port, progName)) == NULL)
{
printf("Couldn't connect to server %s:%i\n",connectTo, port);
CloseLibrary(AMarqueeBase);
exit(RETURN_WARN);
}
printf("StreamGen connected to server %s:%i\n",connectTo, port);
/* Setup */
while(1)
{
struct QMessage * msg;
char data[1000];
/* printf("Streaming %i...\r",count); fflush(stdout); */
/* UNLESS(QStreamOp(session, "streamcount", &count, sizeof(count))) */
UNLESS(QStreamOp(session, "streamcount", data, sizeof(data)))
{
printf("QStreamOp() (even) failed, aborting!\n");
break;
}
count++;
UNLESS(QGo(session, 0L))
{
printf("QGo() failed, aborting!\n");
break;
}
if ((count % 100) == 0)
{
Delay(100);
printf("Next burst (%i)...\n",count);
}
/* Check for any error messages */
while(msg = (struct QMessage *)GetMsg(session->qMsgPort))
{
int stat = msg->qm_Status;
FreeQMessage(session, msg);
if (stat != QERROR_NO_ERROR)
{
printf("Received an error message, closing the connection\n");
exit(RETURN_ERROR);
}
}
}
/* CleanExit called here via the atexit() feature */
}